import request from '../utils/request'

export class RequestClass {
  constructor(){
    this.baseUrl = window.interfacePrefix
  }
  // get基础请求
  getServiceRequest(url: string){
    let baseUrl = this.baseUrl
    return function(data: any,showLoading = true,target = '#app'){
      return request({
        url: baseUrl + url,
        method: "get",
        params: data,
        headers:{showLoading:showLoading,loadingTarget:target}
      })
    }
  }
  // post基础请求
  postServiceRequest(url: string){
    let baseUrl = this.baseUrl
    return function(data: any,showLoading = true,target = '#app'){
      return request({
        url: baseUrl + url,
        method: "post",
        data: data,
        headers:{showLoading:showLoading,loadingTarget:target}
      })
    }
  }
  // get 直接把参数拼接到地址上
  getSplicingServiceRequest(url:string){
    let baseUrl = this.baseUrl
    return function(data:any,showLoading = true,target = '#app'){
      return request({
        url: baseUrl + url + data,
        method:'get',
        headers:{showLoading:showLoading,loadingTarget:target}
      })
    }
  }
}
